﻿using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace SharpCmd.Controls.Viewers
{
    internal class ViewerControl : UserControl, IDisposable
    {
        private bool wordWrap;

        public ViewerControl()
        {
            BackColor = Color.White;
            Dock = DockStyle.Fill;
            this.DoubleBuffered = true;
        }

        protected event EventHandler WordWrapChanged;
        public virtual event EventHandler PercentChanged;

        #region properties
        public string FileName { get; set; }
        public bool WordWrap
        {
            get
            {
                return wordWrap;
            }
            set
            {
                wordWrap = value;
                if (WordWrapChanged != null)
                    WordWrapChanged(null, null);
            }
        }

        public virtual double Percent { get { throw new NotImplementedException(); } }

        //protected StreamReader Reader { get; private set; }
        #endregion

        /// <summary>
        /// Gets an appropriate ViewerControl for specified type
        /// </summary>
        /// <param name="viewerType"></param>
        /// <returns></returns>
        public static ViewerControl Get(ViewerType viewerType)
        {
            switch (viewerType)
            {
                case ViewerType.Text:
                    return new TextViewer();
                case ViewerType.Image:
                    return new ImageViewer();
               // case ViewerType.Media:
               //     return new SoundVideoViewer();
                case ViewerType.Html:
                    return new HTMLViewer();
                default:
                    throw new NotImplementedException();
            }
        }

        public virtual void Display()
        {
            throw new NotImplementedException();
        }

        public virtual void Initialize()
        {
            //Reader = new StreamReader(new FileStream(SelectedFile, FileMode.Open, FileAccess.Read));
        }

        public virtual void OnKeyDown(Keys e)
        {
            throw new NotImplementedException();
        }

        public virtual void Uninitialize()
        {
        }

        protected override void Dispose(bool disposing)
        {
            try
            {
                //Reader.Close();
                //Reader.Dispose();
            }
            catch
            { }
            base.Dispose(disposing);
        }
    }
}